package com.kexio.enterprise.governance.retry.config;

import com.kexio.enterprise.governance.retry.enums.RetryStrategy;

import java.util.List;
import java.util.Map;
import java.util.function.Predicate;

/**
 * 重试配置
 * 
 * @author Kexio
 * @since 1.0.0
 */
public class RetryConfig {
    private int maxAttempts; // 最大重试次数
    private long initialIntervalMs; // 初始间隔时间
    private long maxIntervalMs; // 最大间隔时间
    private double multiplier; // 退避倍数
    private double randomFactor; // 随机因子
    private RetryStrategy strategy; // 重试策略
    private long timeoutMs; // 总超时时间
    private boolean enableJitter; // 是否启用抖动
    private List<Class<? extends Throwable>> retryExceptions; // 重试异常类型
    private List<Class<? extends Throwable>> abortExceptions; // 终止异常类型
    private Predicate<Throwable> retryPredicate; // 重试条件判断
    private List<Long> customIntervals; // 自定义间隔列表
    private boolean enableStatistics; // 是否启用统计
    private Map<String, Object> customParams; // 自定义参数

    public RetryConfig() {
        this.maxAttempts = 3;
        this.initialIntervalMs = 1000;
        this.maxIntervalMs = 30000;
        this.multiplier = 2.0;
        this.randomFactor = 0.1;
        this.strategy = RetryStrategy.EXPONENTIAL_BACKOFF;
        this.timeoutMs = 60000;
        this.enableJitter = true;
        this.enableStatistics = true;
    }

    // Getters and Setters
    public int getMaxAttempts() { return maxAttempts; }
    public void setMaxAttempts(int maxAttempts) { this.maxAttempts = maxAttempts; }
    
    public long getInitialIntervalMs() { return initialIntervalMs; }
    public void setInitialIntervalMs(long initialIntervalMs) { this.initialIntervalMs = initialIntervalMs; }
    
    public long getMaxIntervalMs() { return maxIntervalMs; }
    public void setMaxIntervalMs(long maxIntervalMs) { this.maxIntervalMs = maxIntervalMs; }
    
    public double getMultiplier() { return multiplier; }
    public void setMultiplier(double multiplier) { this.multiplier = multiplier; }
    
    public double getRandomFactor() { return randomFactor; }
    public void setRandomFactor(double randomFactor) { this.randomFactor = randomFactor; }
    
    public RetryStrategy getStrategy() { return strategy; }
    public void setStrategy(RetryStrategy strategy) { this.strategy = strategy; }
    
    public long getTimeoutMs() { return timeoutMs; }
    public void setTimeoutMs(long timeoutMs) { this.timeoutMs = timeoutMs; }
    
    public boolean isEnableJitter() { return enableJitter; }
    public void setEnableJitter(boolean enableJitter) { this.enableJitter = enableJitter; }
    
    public List<Class<? extends Throwable>> getRetryExceptions() { return retryExceptions; }
    public void setRetryExceptions(List<Class<? extends Throwable>> retryExceptions) { this.retryExceptions = retryExceptions; }
    
    public List<Class<? extends Throwable>> getAbortExceptions() { return abortExceptions; }
    public void setAbortExceptions(List<Class<? extends Throwable>> abortExceptions) { this.abortExceptions = abortExceptions; }
    
    public Predicate<Throwable> getRetryPredicate() { return retryPredicate; }
    public void setRetryPredicate(Predicate<Throwable> retryPredicate) { this.retryPredicate = retryPredicate; }
    
    public List<Long> getCustomIntervals() { return customIntervals; }
    public void setCustomIntervals(List<Long> customIntervals) { this.customIntervals = customIntervals; }
    
    public boolean isEnableStatistics() { return enableStatistics; }
    public void setEnableStatistics(boolean enableStatistics) { this.enableStatistics = enableStatistics; }
    
    public Map<String, Object> getCustomParams() { return customParams; }
    public void setCustomParams(Map<String, Object> customParams) { this.customParams = customParams; }
}
